﻿package mortal.game.view.task
{
    import Message.DB.Tables.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gLinkText.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.task.drama.operations.npctalk.*;
    import mortal.mvc.core.*;

    public class TaskIntroduce extends View
    {
        private var _bg:GImageBitmap;
        private var _icon:GImageBitmap;
        private var _txtName:GTextFiled;
        private var _data:TaskDramaTalkData;
        private var _textMaskDesc:TaskDramaTalkMaskText;
        private var _btnClose:GLoadedButton;
        private var _timerId:int;
        private var _datas:Array;
        private static var _instance:TaskIntroduce;

        public function TaskIntroduce()
        {
            this.layer = LayerManager.windowLayer;
            this.isHideDispose = false;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._icon.dispose(param1);
            this._icon = null;
            this._txtName.dispose(param1);
            this._txtName = null;
            this._btnClose.dispose(param1);
            this._btnClose = null;
            if (this._textMaskDesc != null)
            {
                this._textMaskDesc.dispose(param1);
                this._textMaskDesc = null;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(null, 0, 0, this);
            LoaderHelp.setBitmapdata(ImagesConst.TaskIntroduce + ".swf", this._bg);
            this._icon = UIFactory.gImageBitmap(null, 49, 20, this);
            this._txtName = UIFactory.gTextField("", 105, 6, 150, 100, this);
            this._txtName.textColor = GlobalStyle.colorChenUint;
            this._textMaskDesc = UICompomentPool.getUICompoment(TaskDramaTalkMaskText) as TaskDramaTalkMaskText;
            this._textMaskDesc.x = 105;
            this._textMaskDesc.y = 24;
            this.addChild(this._textMaskDesc);
            this._btnClose = UIFactory.gLoadedButton("CloseButtonSmall", 257, 4, 22, 22, null);
            this._btnClose.focusEnabled = true;
            this._btnClose.configEventListener(MouseEvent.CLICK, this.closeBtnClickHandler);
            addChild(this._btnClose);
            return;
        }// end function

        public function showIntroduces(param1:Array) : void
        {
            if (this._timerId > 0)
            {
                clearTimeout(this._timerId);
                this._timerId = -1;
            }
            this._datas = param1.concat();
            this.callNext();
            this.show();
            return;
        }// end function

        private function getNpcTalkData(param1:String, param2:int = 4500) : TaskDramaTalkData
        {
            var _loc_3:* = new TaskDramaTalkData();
            _loc_3.popupTime = 0;
            _loc_3.rowWidth = 150;
            _loc_3.speed = 16;
            _loc_3.talk = param1;
            if (_loc_3.talk == null)
            {
                _loc_3.talk = Language.getString(21236);
            }
            if (param2 <= 0)
            {
                param2 = 4000;
            }
            _loc_3.showTime = param2 + param1.length / _loc_3.speed * 1000;
            _loc_3.talkFontLeading = 0;
            _loc_3.talkFontSize = 12;
            return _loc_3;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(Global.stage.stageWidth - 330, Global.stage.stageHeight - 300);
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            if (this._textMaskDesc != null)
            {
                this._textMaskDesc.dispose();
            }
            if (this._timerId > 0)
            {
                clearTimeout(this._timerId);
                this._timerId = -1;
            }
            return;
        }// end function

        private function callNext(param1 = null) : void
        {
            if (this._datas == null || this._datas.length == 0)
            {
                this.hide();
                return;
            }
            var _loc_2:* = this._datas.shift();
            var _loc_3:* = NPCConfig.instance.getInfoByCode(_loc_2.value1);
            this._txtName.text = _loc_3.name;
            this._textMaskDesc.show(this.getNpcTalkData(_loc_2.htmlText, _loc_2.value2), this.showEnd, false);
            LoaderHelp.setBitmapdata(_loc_3.avatar.toString() + ".png", this._icon);
            return;
        }// end function

        private function showEnd() : void
        {
            this._timerId = setTimeout(this.callNext, 100);
            return;
        }// end function

        protected function closeBtnClickHandler(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public static function get instance() : TaskIntroduce
        {
            if (_instance == null)
            {
                _instance = new TaskIntroduce;
            }
            return _instance;
        }// end function

    }
}
